package com.woniuxy.creditsystem.common.mapper;

import com.github.pagehelper.ISelect;
import com.woniuxy.creditsystem.common.bean.MoneyChannelInfo;
import com.woniuxy.creditsystem.common.bean.PageRequest;
import com.woniuxy.creditsystem.common.bean.ProductInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface MoneyDitchMapper {

    /**
     * 修改渠道--------有空在test条件中加上“xxx！=‘’”
     * @param moneyChannelInfo
     * @return 受影响的行数
     */
    // ditchAllname :'',   //渠道名称
    // ditchSimplenessName:'', //渠道简称
    // companyAllName:'',   //公司全名
    // businessType:'',    //业务类型
    // ditchAdminAccount:'',  //渠道管理员
    // contactName :'',       //联系人姓名
    // contactIdcard:'',     //联系人身份证
    // contactsTelphone :''   //创建人人电话
    @Update("<script>" +
            "update money_channel_info" +
            "<set>" +
            "<if test='m.ditchAllname != null'>" +
            " ditch_allname = #{m.ditchAllname}," +
            "</if>" +
            "<if test='m.contacts != null'>" +
            " contacts = #{m.contacts}," +
            "</if>" +
            "<if test='m.contactsTelphone != null '>" +
            " contacts_telphone= #{m.contactsTelphone}," +
            "</if>" +
            "<if test='m.businessType != null'>" +
            " business_type = #{m.businessType}," +
            "</if>" +
            "<if test='m.ditchAdminAccount != null'>" +
            " ditch_admin_account = #{m.ditchAdminAccount}," +
            "</if>" +
            "<if test='m.ditchSimplenessName  != null'>" +
            " ditch_simpleness_Name = #{m.ditchSimplenessName}," +
            "</if>" +
            "<if test='m.companyAllName != null'>" +
            " company_all_name = #{m.companyAllName}," +
            "</if>" +
            "<if test='m.contactIdcard != null'>" +
            " contact_idcard = #{m.contactIdcard}," +
            "</if>" +
            "</set>" +
            "where id = #{m.id}" +
            "</script>")
    int updaMoneyChannelInfo(@Param("m") MoneyChannelInfo moneyChannelInfo);



    /**
     *新增渠道
     * @param moneyChannelInfo
     * @return
     */
//    INSERT into money_channel_info (id, ditch_nums  , ditch_allname  , status,   contacts ,   contacts_telphone ,
//                                    business_type,ditch_admin_account )
//    VALUES(null,NOW(),'蚂蚁花呗','已禁用','马崽','15325855648','信贷','lz')

//ditchSimplenessName,  companyAllName
    @Insert("insert into money_channel_info " +
            "(id, ditch_nums,ditch_allname,status,contacts,contacts_telphone,business_type,ditch_admin_account,create_time," +
            "ditch_simpleness_Name,company_all_name,contact_name,contact_idcard)" +
            "values(null,#{m.ditchNums},#{m.ditchAllname},#{m.status},#{m.contacts},#{m.contactsTelphone},#{m.businessType}," +
            "#{m.ditchAdminAccount},now()," +
            "#{m.ditchSimplenessName},#{m.companyAllName},#{m.contactName},#{m.contactIdcard})")
    int saveMoneyChannelInfo(@Param("m") MoneyChannelInfo moneyChannelInfo);


    List<ProductInfo> findAllByParams(@Param("p") PageRequest request, @Param("md") MoneyChannelInfo moneyChannelInfo);




    int updaStatusById(MoneyChannelInfo moneyChannelInfo);



    @Select("select id, ditch_allname ditchAllname from money_channel_info")
    List<MoneyChannelInfo> findDitchIdAndDitchAllName();
}
